<?php

namespace admin\modules\buildingOrder\models\forms;

use yii\behaviors\BlameableBehavior;
use yii\helpers\ArrayHelper;
use admin\models\db\BuildingOrders as BuildingOrdersModel;

/**
* BuildingOrders represents the model behind the search form about `admin\models\db\BuildingOrders`.
*/
class BuildingOrders extends BuildingOrdersModel
{
    public function attributeLabels()
    {
        $attributeLabels = parent::attributeLabels();
        $attributeLabels = ArrayHelper::merge($attributeLabels, []);
        return $attributeLabels;
    }

    public function rules()
    {
        $rules = parent::rules();
        foreach ($rules as $k => $v) {
            if ($v[1] == 'required'){
                $rules[$k][0] = array_diff($rules[$k][0], ['province_id', 'city_id']);
            }
        }
        $rules = ArrayHelper::merge($rules, []);
        return $rules;
    }

    public function beforeSave($insert)
    {
        if (parent::beforeSave($insert)) {
            $this->city_id = $this->county->pid;
            $this->province_id = $this->city->pid;
            return true;
        } else {
            return false;
        }
    }
}
